﻿using Storage.DbEntities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Storage.Repositories
{
	public class ExerciseRep : Base.BaseRep<DbEntities.ExerciseDbEntity>
	{
		public ExerciseRep(SQLite.SQLiteAsyncConnection connection) : base(connection) { }

		public async Task<bool> Exists(string exerciseDisplayName)
		{
			var res = await GetByDisplayNameAsync(exerciseDisplayName);
			return res != null;
		}

		public virtual async Task<DbEntities.ExerciseDbEntity> GetByDisplayNameAsync(String displayName)
		{
			if (String.IsNullOrEmpty(displayName))
				return null;

            return await _connection.FindAsync<ExerciseDbEntity>(x => x.DisplayName == displayName);
		}

        public async Task UpdateDisplayNameAsync(Guid exerciseId, String displayName)
        {
            var sqlCommand = string.Format("Update {0} Set DisplayName = '{1}' where Id = '{2}'", TableName, displayName, exerciseId);
            var count = await _connection.ExecuteAsync(sqlCommand);
        }
	}
}
